home *** CD-ROM | disk | FTP | other *** search
/ Internet Pratica / IPRAT_01.iso / ASP / ASPapp Portal / content.asp < prev    next >
Encoding:
Text File  |  2002-03-12  |  12.9 KB  |  462 lines

  1. <!-- #include file="i_utils.asp" -->
  2. <%
  3. %>
  4. <%
  5.     dim keywords
  6.     dim search_sql
  7.     dim articles
  8.     dim CatID
  9.     dim ContentID
  10.     dim user_id
  11.     dim Author
  12.     dim DateAdded
  13.     dim DownloadURL
  14.     dim FileName
  15.     dim LongDesc
  16.     dim RelatedURL
  17.     dim ShortDesc
  18.     dim Title
  19.     dim Cat
  20.     dim detail_content_sql
  21.     dim ContentTypeID
  22.     dim ContentType
  23.     dim view_content_sql
  24.  
  25. sub request_search
  26. ''' request expected input parameters for this form
  27.     keywords = request("keywords")
  28. end sub
  29. sub request_detail_content
  30. ''' request expected input parameters for this form
  31.     CatID = request("CatID")
  32.     ContentID = request("ContentID")
  33.     user_id = request("user_id")
  34.     Author = request("Author")
  35.     DateAdded = request("DateAdded")
  36.     DownloadURL = request("DownloadURL")
  37.     FileName = request("FileName")
  38.     LongDesc = request("LongDesc")
  39.     RelatedURL = request("RelatedURL")
  40.     ShortDesc = request("ShortDesc")
  41.     Title = request("Title")
  42.     Cat = request("Cat")
  43. end sub
  44. sub request_view_content
  45. ''' request expected input parameters for this form
  46.     ContentID = request("ContentID")
  47.     ContentTypeID = request("ContentTypeID")
  48.     CatID = request("CatID")
  49.     Author = request("Author")
  50.     ContentType = request("ContentType")
  51.     Title = request("Title")
  52.     DateAdded = request("DateAdded")
  53.     ShortDesc = request("ShortDesc")
  54. end sub
  55.  
  56. sub validate_search
  57. ''' request and validate data entered from this form
  58.     keywords = trim(request("keywords"))
  59. end sub
  60. sub validate_detail_content
  61. ''' request and validate data entered from this form
  62.     CatID = trim(request("CatID"))
  63.     ContentID = trim(request("ContentID"))
  64.     user_id = trim(request("user_id"))
  65.     Author = trim(request("Author"))
  66.     DateAdded = trim(request("DateAdded"))
  67.     if DateAdded <> "" AND (not isdate(DateAdded)) then
  68.         error_list.add "484908date","DateAdded must be a valid date (MM/DD/YY)."
  69.         b_error = true
  70.     end if
  71.     DownloadURL = trim(request("DownloadURL"))
  72.     FileName = trim(request("FileName"))
  73.     LongDesc = trim(request("LongDesc"))
  74.     RelatedURL = trim(request("RelatedURL"))
  75.     ShortDesc = trim(request("ShortDesc"))
  76.     Title = trim(request("Title"))
  77.     Cat = trim(request("Cat"))
  78. end sub
  79. sub validate_view_content
  80. ''' request and validate data entered from this form
  81.     ContentID = trim(request("ContentID"))
  82.     ContentTypeID = trim(request("ContentTypeID"))
  83.     CatID = trim(request("CatID"))
  84.     Author = trim(request("Author"))
  85.     ContentType = trim(request("ContentType"))
  86.     Title = trim(request("Title"))
  87.     DateAdded = trim(request("DateAdded"))
  88.     if DateAdded <> "" AND (not isdate(DateAdded)) then
  89.         error_list.add "484920date","DateAdded must be a valid date (MM/DD/YY)."
  90.         b_error = true
  91.     end if
  92.     ShortDesc = trim(request("ShortDesc"))
  93. end sub
  94.  
  95.  
  96. sub db_select_detail_content
  97.     sql = "SELECT " & _ 
  98.     "Author, " & _ 
  99.     "Cats.CatID, " & _ 
  100.     "ContentID, " & _ 
  101.     "DateAdded, " & _ 
  102.     "DownloadURL, " & _ 
  103.     "FileName, " & _ 
  104.     "LongDesc, " & _ 
  105.     "RelatedURL, " & _ 
  106.     "ShortDesc, " & _ 
  107.     "Title, " & _ 
  108.     "user_id, " & _ 
  109.     "Cat FROM content,Cats" & _ 
  110.     " WHERE content.CatId = Cats.CatId AND " & _ 
  111.     "ContentID = " & to_sql(ContentID,"number") & ""
  112.     on error resume next
  113.     set rs = cn.Execute(sql)
  114.     if err.number <> 0 then
  115.         b_error = true
  116.     elseif rs.EOF then
  117.         b_results = false
  118.     else
  119.         CatID = rs("CatID")
  120.         ContentID = rs("ContentID")
  121.         user_id = rs("user_id")
  122.         Author = rs("Author")
  123.         DateAdded = rs("DateAdded")
  124.         DownloadURL = rs("DownloadURL")
  125.         FileName = rs("FileName")
  126.         LongDesc = rs("LongDesc")
  127.         RelatedURL = rs("RelatedURL")
  128.         ShortDesc = rs("ShortDesc")
  129.         Title = rs("Title")
  130.         Cat = rs("Cat")
  131.     end if
  132.     rs.Close
  133.     on error goto 0
  134. end sub
  135. sub db_insert_detail_content
  136.     sql = "INSERT INTO content" & _ 
  137.     "(" & _ 
  138.     "CatID," & _ 
  139.     "user_id," & _ 
  140.     "Author," & _ 
  141.     "DateAdded," & _ 
  142.     "DownloadURL," & _ 
  143.     "FileName," & _ 
  144.     "LongDesc," & _ 
  145.     "RelatedURL," & _ 
  146.     "ShortDesc," & _ 
  147.     "Title" & _ 
  148.     ") VALUES (" & to_sql(CatID,"number") & "," & _ 
  149.     "" & to_sql(user_id,"number") & "," & _ 
  150.     "" & to_sql(Author,"text") & "," & _ 
  151.     "" & to_sql(DateAdded,"text") & "," & _ 
  152.     "" & to_sql(DownloadURL,"text") & "," & _ 
  153.     "" & to_sql(FileName,"text") & "," & _ 
  154.     "" & to_sql(LongDesc,"text") & "," & _ 
  155.     "" & to_sql(RelatedURL,"text") & "," & _ 
  156.     "" & to_sql(ShortDesc,"text") & "," & _ 
  157.     "" & to_sql(Title,"text") & ")" & _ 
  158.     ""
  159.     'response.write sql
  160.     on error resume next
  161.     cn.Execute(sql)
  162.     if err.Number <> 0 then
  163.         b_error = true
  164.     else
  165.         set rs = cn.Execute("SELECT @@IDENTITY")
  166.         ContentID = rs(0)
  167.         rs.Close
  168.         set rs = cn.Execute("SELECT @@IDENTITY")
  169.         ContentID = rs(0)
  170.         rs.Close
  171.     end if
  172.     on error goto 0
  173. end sub
  174. sub db_update_detail_content
  175.     sql = "UPDATE content SET " & _ 
  176.     "CatID = " & to_sql(CatID,"number") & ", " & _ 
  177.     "user_id = " & to_sql(user_id,"number") & ", " & _ 
  178.     "Author = " & to_sql(Author,"text") & ", " & _ 
  179.     "DateAdded = " & to_sql(DateAdded,"text") & ", " & _ 
  180.     "DownloadURL = " & to_sql(DownloadURL,"text") & ", " & _ 
  181.     "FileName = " & to_sql(FileName,"text") & ", " & _ 
  182.     "LongDesc = " & to_sql(LongDesc,"text") & ", " & _ 
  183.     "RelatedURL = " & to_sql(RelatedURL,"text") & ", " & _ 
  184.     "ShortDesc = " & to_sql(ShortDesc,"text") & ", " & _ 
  185.     "Title = " & to_sql(Title,"text") & " WHERE " & _ 
  186.     "ContentID = " & to_sql(ContentID,"number") & ""
  187.     'response.write sql
  188.     on error resume next
  189.     cn.execute(sql)
  190.     if err.number <> 0 then
  191.         b_error = true
  192.     end if
  193.     on error goto 0
  194. end sub
  195. sub db_delete_detail_content
  196.     sql = "DELETE FROM content" & _ 
  197.     " WHERE " & _ 
  198.     "ContentID = " & to_sql(ContentID,"number") & ""
  199.     'response.write sql
  200.     on error resume next
  201.     cn.Execute(sql)
  202.     if err.number <> 0 then
  203.         b_error = true
  204.     end if
  205.     on error goto 0
  206. end sub
  207. sub db_select_view_content
  208.     if do_search = "1" then
  209.     request_view_content
  210.     view_content_sql = "SELECT " & _ 
  211.     "content.ContentID, " & _ 
  212.     "Content.ContentTypeID, " & _ 
  213.     "Content.CatID, " & _ 
  214.     "content.Author, " & _ 
  215.     "ContentTypes.ContentType, " & _ 
  216.     "content.Title, " & _ 
  217.     "content.DateAdded, " & _ 
  218.     "content.ShortDesc FROM (content LEFT JOIN ContentTypes ON content.contenttypeid = ContentTypes.contenttypeid) " & _ 
  219.     " WHERE (Title LIKE '%" & keywords & "%' OR ShortDesc LIKE '%" & keywords & "%')"
  220.     else
  221.     view_content_sql = "SELECT " & _ 
  222.     "content.ContentID, " & _ 
  223.     "Content.ContentTypeID, " & _ 
  224.     "Content.CatID, " & _ 
  225.     "content.Author, " & _ 
  226.     "ContentTypes.ContentType, " & _ 
  227.     "content.Title, " & _ 
  228.     "content.DateAdded, " & _ 
  229.     "content.ShortDesc FROM (content LEFT JOIN ContentTypes ON content.contenttypeid = ContentTypes.contenttypeid) " & _ 
  230.     "WHERE ContentType = 'Article' OR ContentType = 'Tutorial' OR ContentType = 'Example / Code Snippet'" & _ 
  231.     ""
  232.     end if
  233.     if request("sortby") <> "" AND inStr(lcase(view_content_sql),"order by") = 0 then view_content_sql = view_content_sql + " ORDER BY " & request("sortby")
  234. end sub
  235. sub db_delete_view_content
  236.     sql = "DELETE FROM Content" & _ 
  237.     " WHERE " & _ 
  238.     "ContentTypeID = " & to_sql(ContentTypeID,"number") & ""
  239.     'response.write sql
  240.     on error resume next
  241.     cn.Execute(sql)
  242.     if err.number <> 0 then
  243.         b_error = true
  244.     end if
  245.     on error goto 0
  246. end sub
  247.  
  248. do_search = request("do_search")
  249. ''' request form keys
  250. keywords = request("keywords")
  251. ContentID = request("ContentID")
  252. ContentTypeID = request("ContentTypeID")
  253. ''' request action
  254. action = lcase(request("action"))
  255. ''' action case handler
  256. select case action
  257.  
  258. case "select_detail_content"
  259. '  select the requested key record from database
  260. if ContentID <> "" then
  261.     db_select_detail_content
  262. else
  263.     b_error = true
  264.     error_list.add "edit_detail_content", "Specify record to select."
  265. end if
  266.  
  267.  
  268. case "insert_detail_content"
  269. '  request form data and insert a new record into database
  270.  
  271. validate_detail_content
  272. if not b_error then
  273.     db_insert_detail_content
  274. end if
  275.  
  276.  
  277.  
  278. case "update_detail_content"
  279. '  request form data and update an existing database record
  280. validate_detail_content
  281. if not b_error then
  282. if ContentID <> "" then
  283.     db_update_detail_content
  284. else
  285.     b_error = true
  286.     error_list.add "update_detail_content", "Specify record to update."
  287. end if
  288. end if
  289.  
  290.  
  291. case "delete_detail_content"
  292. '  delete the requested key database record
  293. if ContentID <> "" then
  294.     db_delete_detail_content
  295.     response.redirect request.servervariables("script_name") & "?msg=The+record+was+deleted."
  296. else
  297.     b_error = true
  298.     error_list.add "delete_detail_content", "Specify record to delete."
  299. end if
  300.  
  301. case "display_detail_content"
  302.     display_detail_content = true
  303.  
  304. end select
  305.  
  306. '  no action was specified, so handle the default case(s)
  307. if ContentID <> "" then
  308.     db_select_detail_content
  309.     display_detail_content = true 
  310. end if
  311. db_select_view_content
  312.  
  313. %>
  314.  
  315. <!-- #include file='i_header.asp' -->
  316. <!-- #include file='i_menu.asp' -->
  317.  
  318.  
  319. <%
  320. display_errs
  321. display_msg
  322. %>
  323.  
  324. <table  >
  325. <form name="search" action="content.asp" method="get" >
  326. <tr>
  327.     <td class='labelTD'>search articles //</td>
  328.     <td class='dataTD' width='140' nowrap>
  329.         <input type=text  name="keywords" size="" maxlength="" value="<% =keywords%>"><input class=cmd type=submit name=search value='GO'>
  330.     </td>
  331. </tr>
  332. <input type=hidden name="do_search" value="1">
  333.  
  334. </form>
  335. </table>
  336.  
  337.  
  338. <table class=headerTable>
  339. <tr>
  340. <td class=headerTD>
  341.         <A href='content.asp'>Articles</A>
  342.  
  343. <% if contenttypeid <> "" then %>
  344. <% set rs = cn.execute("SELECT contenttype from contenttypes where contenttypeid = " & contenttypeid & "") %>
  345. › <A href='content.asp?ContentTypeid=<% =ContentTypeId %>'><% =rs("ContentType") %></A>
  346. <% rs.close %>
  347. <% end if %>
  348.  
  349.  
  350. </td>
  351. </tr>
  352. </table>
  353. <! -- only display the detail form when the grid form is not displayed -->
  354. <% if ContentID <> "" OR display_detail_content then %>
  355. <P>
  356. <table class='headerTable'>
  357. <tr>
  358. <td class='headerTD'>
  359. <B><% =Title %></B>
  360. </td>
  361. </tr>
  362. </table>
  363. <table  >
  364. <form name="detail_content" action="content.asp" method="get" >
  365. <tr>
  366. <td><i>by <% =Author %></i></td>
  367. <td align=right><% =Cat %> รกรก <% =DateAdded %></td>
  368. </tr>
  369. <tr>
  370. <td colspan=2>
  371. <% =LongDesc %>
  372. </td>
  373. </tr>
  374. <tr>
  375. <td colspan=2>
  376. <br>
  377. <% =RelatedURL %>
  378. <% =DownloadURL %>
  379. </td>
  380. </tr>
  381.  
  382. </form>
  383. </table>
  384.  
  385. <%end if%>
  386. <! -- only display the grid when the display form is not displayed -->
  387. <% if display_detail_content <> true then %>
  388. <%
  389.  
  390. page_no = request("page_no")
  391. if page_no = "" then page_no = 1
  392.  
  393. if view_content_sql <> "" then
  394.     cmd.CommandText = view_content_sql
  395.     rs.Filter = ""
  396.     if ContentTypeID <> "" then rs.Filter = "ContentTypeID = " & to_sql(ContentTypeID,"number")
  397.     rs.CursorLocation = 3
  398.     rs.CacheSize = 5
  399.     rs.Open cmd
  400.     if not rs.EOF then
  401.             rs.MoveFirst
  402.             rs.PageSize = 20
  403.             max_count = cInt(rs.PageCount)
  404.             num_recs = rs.RecordCount
  405.             rs.AbsolutePage = page_no
  406.             results = true
  407.     else
  408.         results = false
  409.         rs.Close
  410.     end if
  411. else
  412.     results = false
  413. end if
  414. rec_count = 0
  415.  
  416. %>
  417.  
  418. <table class='headerTable'>
  419. <tr>
  420. <td class='headerTD'>
  421. <% =num_recs %> articles found...
  422. </td>
  423. </tr>
  424. </table>
  425. <%
  426.  
  427. if results = true then
  428.  
  429. %>
  430.  
  431. <table  >
  432. <form name="view_content" action="content.asp" method="get" >
  433. <%
  434.  
  435. do while not rs.EOF and rec_count < rs.Pagesize
  436.  
  437. ':: read db record
  438. on error resume next
  439. ContentID = rs("ContentID")
  440. ContentTypeID = rs("ContentTypeID")
  441. CatID = rs("CatID")
  442. Author = rs("Author")
  443. ContentType = rs("ContentType")
  444. Title = rs("Title")
  445. DateAdded = rs("DateAdded")
  446. ShortDesc = rs("ShortDesc")
  447. on error goto 0
  448.  
  449. %>
  450. <tr>
  451.     <td>
  452.     <div style="{font-size:11px;font-weight:800;}"><A href='content.asp?contentid=<% =contentid %>'><% =Title %></A></div>
  453.     // by <I><% =Author %></I>, <% =DateAdded %><br>
  454.     // type <I><A href='content.asp?ContentTypeId=<% =ContentTypeId %>'><% =ContentType %></A></I><br>
  455.     <br>
  456.     <% =ShortDesc %>
  457.     <br><br>
  458.     </td>
  459. </tr>
  460. <%
  461.  
  462. rs.MoveNext
  463. rec_count = rec_count + 1
  464. loop
  465. rs.Close
  466.  
  467. %>
  468.  
  469. </form>
  470. </table>
  471. <%
  472.  
  473. else
  474.  
  475. %>
  476.  
  477.     no matches were found.
  478.  
  479. <%
  480.  
  481. end if
  482.  
  483. %>
  484.  
  485. <%
  486.  if max_count > 1 then 
  487. %>
  488.  
  489. <!-- paging footer -->
  490. <TABLE class=HeaderTable >
  491.     <tr>
  492.         <td width="20%" class=HeaderTD>
  493.             <% if page_no > 1 then %>
  494.             <a class=HeaderFont href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =page_no-1 %>&sortby=<% =request("sortby") %>">PREV</a>
  495.             <% else %>            <% end if %>        </td>
  496.         <td align=center class=HeaderTD>
  497.             Page 
  498.             <% for i = 1 to max_count %>
  499.             <% if i = cint(page_no) then %>
  500.             <b><%=i%></b>
  501.             <% else %>
  502.             <a class=HeaderFont href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =i %>&sortby=<% =request("sortby") %>"><%=i%></a>
  503.             <% end if %>
  504.             <%next %>
  505.         </td>
  506.         <td align=right width="20%" class=HeaderTD>
  507.             <% if cInt(page_no) < cInt(max_count) then %>
  508.             <a class=HeaderFont href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =page_no+1 %>&sortby=<% =request("sortby") %>">NEXT</a>
  509.             <% end if %>
  510.         </td>
  511.     </tr>
  512. </TABLE>
  513. <% end if %>
  514.  
  515.  
  516. <%end if%>
  517.  
  518. <!-- #include file=i_footer.asp -->
  519.  
  520.  
  521. <%
  522. ':: assure that any db resources are freed
  523. on error resume next
  524. rs.Close
  525. set rs = NOTHING
  526. cn.Close
  527. set cn = NOTHING
  528. user_cn.Close
  529. set user_cn = NOTHING
  530. on error goto 0
  531. %>
  532.